package com.settlement.system.model.param;

import com.alibaba.excel.annotation.ExcelIgnoreUnannotated;
import com.alibaba.excel.annotation.write.style.HeadFontStyle;
import com.alibaba.excel.annotation.write.style.HeadRowHeight;
import com.alibaba.excel.annotation.write.style.HeadStyle;
import com.settlement.system.common.util.common.Md5Utils;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.hibernate.validator.constraints.NotBlank;

import java.io.Serializable;

/**
 * 爱库存删数据接口
 * @author xiaochuan
 * @since 2021-03-09
 */
@Data
@ExcelIgnoreUnannotated
@HeadStyle(fillBackgroundColor = 9,fillForegroundColor = 9)
@HeadRowHeight(value = 20)
@HeadFontStyle(fontHeightInPoints = 14)
public class AkcDeleteDataApiRequestParams extends ApiParams implements Serializable {


    /**
     * 活动ID
     */
    @ApiModelProperty(value = "活动ID",required = true)
    @NotBlank(message = "活动ID不能为空")
    private String activityId;

    /**
     * 活动类型
     */
    @ApiModelProperty(value = "活动类型",required = true)
    @NotBlank(message = "活动类型不能为空")
    private String activityType;

    /**
     * code
     */
    @ApiModelProperty(value = "code",required = true)
    @NotBlank(message = "code不能为空")
    private String code;

    @Override
    public String verifyBean(){
        final String shoukuan = "首款";
        final String weikuan = "尾款";
        if(!shoukuan.equals(activityType) &&!weikuan.equals(activityType)){
            return "activityType 字段的值只能是首款或者尾款";
        }
        if(!checkCodeMd5(code)){
            return "code校验失败。";
        }
        return null;
    }

    public boolean checkCodeMd5(String code){
        return Md5Utils.getMd5(activityId+activityType).equalsIgnoreCase(code);
    }


}
